﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using SlamDunk.CMS.Model.DataModel;

namespace SlamDunk.CMS.Model.ViewModel
{
    /// <summary>
    /// User视图模型类（添加/修改用）
    /// </summary>
    public class UserViewForManage
    {
        #region 01.属性——Id
        /// <summary>
        /// 属性——Id
        /// </summary>
        public int Id { get; set; }
        #endregion

        #region 02.属性——用户名
        /// <summary>
        /// 属性——用户名
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [StringLength(16, ErrorMessage = "内容过长")]
        [DisplayName("用户名")]
        public string UserName { get; set; }
        #endregion

        #region 03.属性——密码
        /// <summary>
        /// 属性——密码
        /// </summary>
        [Required(ErrorMessage = "必填")]
        [StringLength(32, ErrorMessage = "内容过长")]
        [DisplayName("密码")]
        public string Password { get; set; }
        #endregion

        #region 04.属性——真实姓名
        /// <summary>
        /// 属性——真实姓名
        /// </summary>
        [StringLength(32, ErrorMessage = "内容过长")]
        [DisplayName("真实姓名")]
        public string RealName { get; set; }
        #endregion

        #region 05.属性——联系电话
        /// <summary>
        /// 属性——联系电话
        /// </summary>
        [StringLength(16, ErrorMessage = "内容过长")]
        [DisplayName("联系电话")]
        [RegularExpression(@"^1[34578]{1}\d{9}$", ErrorMessage = "格式不正确")]
        public string PhoneNumber { get; set; }
        #endregion

        #region 06.属性——电子邮箱
        /// <summary>
        /// 属性——电子邮箱
        /// </summary>
        [StringLength(32, ErrorMessage = "内容过长")]
        [DisplayName("电子邮箱")]
        [RegularExpression(@"^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$", ErrorMessage = "格式不正确")]
        public string Email { get; set; }
        #endregion

        #region 07.属性——创建时间
        /// <summary>
        /// 属性——创建时间
        /// </summary>
        [DisplayName("创建时间")]
        public string AddTime { get; set; }
        #endregion

        #region 08.方法——转换为数据模型
        /// <summary>
        /// 方法——转换为数据模型
        /// </summary>
        /// <returns>数据模型</returns>
        public User ToDataModel()
        {
            return new User()
            {
                Id = this.Id,
                UserName = this.UserName,
                Password = this.Password,
                RealName = this.RealName,
                PhoneNumber = this.PhoneNumber,
                Email = this.Email,
                AddTime = DateTime.Now
            };
        }
        #endregion
    }
}
